<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    li{
      height:50px;
      margin-top:5px;
      background: pink;
    }
  </style>
</head>
<body>
  <div id="app">
    <button @click="changeLength">改变length</button>
    <ul>
      <li v-for="(el,index) in arr" @click="change(index)" :key="el">
        {{el}}
      </li>
    </ul>
    <hr>
    <ul>
      <li v-for="(el,index) in arr2" @click="change2(index)" :key="index">
        {{el.a}}
      </li>
    </ul>
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        arr: [1,2,3,4],
        arr2: [
          {
            a:10
          },
          {
            a:20
          },
          {
            a:30
          }
        ]
      },
      methods: {
        change(index){
        /*   this.arr[index] = 100;
          console.log(this.arr) */
          this.$set(this.arr,index,100)
        },
        change2(index){
          this.arr2[index].a = 200;
        },
        changeLength () {
          this.arr.length = this.arr.length-1;
          console.log(this.arr)
        }
      }
    })
  </script>
</body>
</html>